package Demo;

public class Demo02 {
    public static void main(String[] args) {
        // 2.二维数组如何通过下角标操作指定的元素(取值和赋值)
        //可以把二维数组当作一个表格来看待

        int[][] arr1 = new int[][]{{10,20,30},{40,50},{60}};

        //取值
        System.out.println(arr1[0][0]);
        System.out.println(arr1[1][1]);
        System.out.println(arr1[2][0]);

        String[][] str = new String[3][3];

        //str[0] = {"a","b","c"}; 不能一次附多值

        //赋值
        str[0][0] = "1";
        str[0][1] = "2";
        str[0][2] = "3";

        str[1][0] = "4";
        str[1][1] = "5";
        str[1][2] = "6";

        str[2][0] = "7";
        str[2][1] = "8";
        str[2][2] = "9";

        System.out.println(str[1][2]);

        System.out.println("-----------------");
        //获取二维数组的长度
        System.out.println(str.length);
        //获取二维数组里面一维数组的长度
        System.out.println(str[0].length);

        System.out.println("-----------------");
        //遍历二维数组 双层for循环

        //二维数组的长度
        for(int i = 0; i < str.length; i++){

            //System.out.println(str[i]); 这是二维数组中一维数组的内存地址

            //二维数组中一维数组的长度
            for(int j = 0; j < str[i].length; j++){

                System.out.print(str[i][j] + " ");

            }
            System.out.println();
        }


    }
}
